/**
 * Created by cuppi on 2017/6/30.
 */

var express = require('express');
var router = express.Router();

var path = require('path');
var qiniu = require('qiniu');

router.get('/', function (req, res, next) {
    // var accessKey = 'qoFeXFeK9LuEYXVav8e6KVibE5te3WpxUt b_jaPZ';
    // var secretKey = '_y7xBbKbobKGHuI31qxR_bFwFWBoTRtZBGSifHMP';
    // var mac = new qiniu.auth.digest.Mac(accessKey, secretKey);
    //
    // var options = {
    //     scope: 'uglyfilm-test',
    // };
    // var putPolicy = new qiniu.rs.PutPolicy(options);
    // var uploadToken = putPolicy.uploadToken(mac);
    // console.log(uploadToken);
    // res.json({data: uploadToken, errorCode: 0, message: ''});
});

router.post('/', function (req, res, next) {
    var accessKey = 'qoFeXFeK9LuEYXVav8e6KVibE5te3WpxUtb_jaPZ';
    var secretKey = '_y7xBbKbobKGHuI31qxR_bFwFWBoTRtZBGSifHMP';
    var mac = new qiniu.auth.digest.Mac(accessKey, secretKey);

    var options = {
        scope: 'uglyfilm-test',
    };
    var putPolicy = new qiniu.rs.PutPolicy(options);
    var uploadToken = putPolicy.uploadToken(mac);
    console.log(uploadToken);
    res.json({data: uploadToken, errorCode: 0, message: ''});
});

module.exports = router;